package com.yndsoft.jc.ui.memberpage.myorder;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.yndsoft.jc.R;
import com.yndsoft.jc.activity.BaseActivity;
import com.yndsoft.jc.model.MemberComment;
import com.yndsoft.jc.model.ReturnMsg;
import com.yndsoft.jc.supplier.utils.ToastUtil;
import com.yndsoft.jc.ui.net.util.ProgressSubscriber;
import com.yndsoft.jc.utils.ConstantValues;
import com.yndsoft.jc.widget.StarBar;

import butterknife.Bind;

/**
 * Created by hasee on 2017/12/8.评价
 */

public class EvaluateActivity extends BaseActivity implements View.OnClickListener {

    @Bind(R.id.base_backBtn)
    RelativeLayout base_backBtn;
    @Bind(R.id.base_title)
    TextView base_title;
    @Bind(R.id.starBar)
    StarBar starBar;
    @Bind(R.id.comment_content)
    EditText comment_content;

    @Bind(R.id.submint_comment)
    Button submint_comment;
    private int orderID;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_evaluate);

        setViews();
        setListener();
    }

    private void setViews() {
        orderID = getIntent().getIntExtra(ConstantValues.EVALUATE_INTENT, 100001);
        base_title.setText(getResources().getString(R.string.evaluate_order));
        starBar.setIntegerMark(true);
    }

    private void setListener() {
        base_backBtn.setOnClickListener(this);
        submint_comment.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.base_backBtn:
                finish();
                break;
            case R.id.submint_comment:
                submitComm();
                break;
        }
    }

    private void submitComm() {
        MemberComment memberComment = new MemberComment();
        memberComment.setNote(comment_content.getText().toString());
        memberComment.setStar((int) starBar.getStarMark());
        memberComment.setOid(orderID);
        mHttpUtil.getOrderComment(new ProgressSubscriber<ReturnMsg>(mContext) {
            @Override
            public void next(ReturnMsg returnMsg) {
                switch (returnMsg.getCode()) {
                    case 0:
                        ToastUtil.show(mContext, "提交失败");
                        break;
                    case 1:
                        ToastUtil.show(mContext, "提交成功");
                        finish();
                        break;
                }
            }
        }, "comment", mSession.getUserInfo().getId(), new Gson().toJson(memberComment));
    }
}
